<template>
	<view class="page">
		<view class="use-uni-list">
			<view class="use-uni-list-cell">
				<view class="uni-list-cell-navigate uni-navigate-right" hover-class="uni-list-cell-hover" @click="updatatouxiang">
					头像
					<image class="userhead" :src="baseURL+data.avatar" ></image>
				</view>
			</view>
			<view class="use-uni-list-cell">
				<view class="uni-list-cell-navigate uni-navigate-right" @click="upnickName">
					昵称
					<view class="rigthText">{{ data.NAME }}</view>
				</view>
			</view>
			<view class="use-uni-list-cell">
				<view class="uni-list-cell-navigate">
					手机
					<view class="rigthText">{{ data.ACCOUNT }}</view>
				</view>
			</view>
		</view>
		<button type="warn" class="loginout" @click="downline">注销登录</button>
	</view>
</template>

<script>
export default {
	data() {
		return {
			data:'',
			baseURL:this.$API.baseURL,
			deptid:uni.getStorageSync("deptid"),
		};
	},
	onShow: function() {
		// #ifdef APP-PLUS
		/* 隐藏凸起图标 */
		var icon = plus.nativeObj.View.getViewById("icon");
		setTimeout(function() {
			if(icon){icon.hide();}
		}, 100);
		// #endif
		this.getUserDetail();
	},
	methods: {
		updatatouxiang(){//修改头像
			var _this = this;
			uni.chooseImage({
				sourceType: ["camera", "album"],
				sizeType: "compressed",
				count: 1,
				success: (res) => {
					_this.tempFilePaths = res.tempFilePaths;
					// console.log(res.tempFilePaths[0])
					uni.uploadFile({
						url: this.$API.upload,
						name: 'file',
						filePath: res.tempFilePaths[0],
						success: function(res) {
							var logo = JSON.parse(res.data);
							_this.uploadLogo(logo)
						},
						fail: function(res) {
							uni.showToast({
								title:"上传失败",
								icon:'none'
							})
							// console.log('上传失败', res);
						}
					});
				}
			});
		},
		uploadLogo(e){
			var _this = this;
			uni.request({
				url:this.$API.uploadUserLogo,
				data:{
					userid:uni.getStorageSync("userid"),
					logo:e.fileName
				},
				method:"GET",
				header:this.$API.get_head(),
				success: (res) => {
					if(res.data.success){
						_this.findCompanyInfo();
					}
					uni.showToast({
						title:res.data.message,
						icon:"none"
					})
				},
				fail: () => {
					uni.showToast({
						title:"加载失败",
						icon:'none'
					})
				}
			})
		},
		//获取资料
		getUserDetail(){
			var _this=this;
			uni.request({
				url:this.$API.getUserDetail,
				method:"POST",
				data:{
					userid:uni.getStorageSync("userid"),
				},
				header:this.$API.get_head(),
				success: (res) => {
					_this.data=res.data.data;
				},
				fail: () => {
					uni.showToast({
						title:"加载失败",
						icon:'none'
					})
				 }
			})
		},
		gopage: function(url) {
			uni.navigateTo({
				url: url
			});
		},
		upnickName: function() {
			let arr = {
				title: '修改昵称',
				url: this.$API.editName,
				data: [
					{
						userid: 'nickName',
						title: '昵称',
						type: 'text'
					}
				]
			};
			let str = JSON.stringify(arr);
			uni.navigateTo({
				url: '/pages/newpages/infoFrom?obj=' + str
			});
		},
		//注销登录
		downline(){
			uni.removeStorageSync('userid');
			uni.removeStorageSync('deptid');
			uni.removeStorageSync('phone');
			uni.removeStorageSync('company');
			this.$appjs.jim.loginOut()
			uni.reLaunch({
				url:'/pages/login/login'
			})	
		},
	}
};
</script>

<style lang="scss">
	.loginout{
		width:75%;
		margin:30upx auto;
	}
.use-uni-list {
	background-color: #ffffff;
	position: relative;
	width: 100%;
	display: flex;
	flex-direction: column;
	.use-uni-list-cell {
		position: relative;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		.uni-list-cell-navigate {
			padding: 22upx 30upx;
			line-height: 48upx;
			position: relative;
			display: flex;
			box-sizing: border-box;
			width: 100%;
			flex: 1;
			justify-content: space-between;
			align-items: center;
			.userhead {
				float: right;
				margin-right: 36upx;
				width: 100upx;
				height: 100upx;
				border-radius: 50%;
				vertical-align: middle;
			}
		}

		.uni-list-cell-navigate {
			padding-right: 36upx;
		}
		.uni-list-cell-hover {
			background-color: #eee;
		}
	}
}
.use-uni-list:after {
	position: absolute;
	z-index: 10;
	right: 0;
	bottom: 0;
	left: 0;
	height: 1upx;
	content: '';
	-webkit-transform: scaleY(0.5);
	transform: scaleY(0.5);
	background-color: #c8c7cc;
}

.rigthText {
	margin-right: 36upx;
}
.uni-list-cell-navigate {
	font-size: 35upx;
	line-height: inherit;
}
</style>
